package com.steak.system.service.security.impl;

import com.steak.system.common.exception.BusinessException;
import com.steak.system.common.exception.EmBusinessError;
import com.steak.system.mapper.UserDOMapper;
import com.steak.system.pojo.dataobject.UserDO;
import com.steak.system.pojo.dto.UserDTO;
import com.steak.system.service.security.UserService;
import com.steak.system.util.ConvertUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Service;

import javax.jms.JMSException;
import javax.jms.ObjectMessage;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDOMapper userDOMapper;

    @Override
    public UserDTO getUserInfo(String userId) throws BusinessException {
        UserDO userDO = userDOMapper.queryUserInfoByUsername(userId);
        if (userDO == null){
            throw new BusinessException(EmBusinessError.USER_NOT_EXIST);
        }
        UserDTO userDTO = (UserDTO) ConvertUtils.DoToDto(userDO,new UserDTO());
        if (userDO.getRoleId().equals("1")){
            userDTO.setRoles("admin");
        }else if(userDO.getRoleId().equals("2")){
            userDTO.setRoles("artisan");
        }else if (userDO.getRoleId().equals("3")){
            userDTO.setRoles("worker");
        }else if (userDO.getRoleId().equals("4")){
            userDTO.setRoles("student");
        }else if(userDO.getRoleId().equals("5")){
            userDTO.setRoles("helper");
        }
        return userDTO;
    }

//    /**
//     * 注册
//     * @param objectMessage
//     */
//    @Override
//    @JmsListener(destination = "${MyQueue}")
//    public void register(ObjectMessage objectMessage) throws JMSException {
//        UserDO userDO = (UserDO) objectMessage.getObject();
//        System.out.println("插入数据库");
//        userDOMapper.insertSelective(userDO);
//    }
}
